package com.ice.app.system.utils;

import org.apache.commons.lang3.StringUtils;

import com.iceframework.core.support.cache.ICacheService;
import com.iceframework.core.utils.JsonUtils;
import com.iceframework.core.utils.SpringContextUtils;

public class CacheUtils {

	public static final String PREFIX = "Cache:";

	public static void cacheObj(String key, Object obj) {
		ICacheService cacheService = SpringContextUtils.getBean("cacheService", ICacheService.class);
		cacheService.set(PREFIX + key, obj);
	}
	
	public static <T> T getObj(String key, Class<T> clazz) {
		ICacheService cacheService = SpringContextUtils.getBean("cacheService", ICacheService.class);
		String cacheData = cacheService.get(PREFIX + key);
		T t = null;
		try {
			if (StringUtils.isNotBlank(cacheData)) {
				t = JsonUtils.convertString2Obj(cacheData, clazz);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return t;
	}
}
